package org.logan.sample.web.base.engine;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.logan.sample.base.cache.redis.RedisCacheManager;
import org.logan.sample.web.main.service.common.SysConfigs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 系统初始化
 * 
 * @author xulongjun 2015-10-30
 * @qq 425018553
 */
@Component
public class WebSampleInit {
	private final Logger logger = LoggerFactory.getLogger(WebSampleInit.class);
	@Resource
	EventManager eventManager;
	@Resource
	SysConfigs sysConfigs;

	/**
	 * 初始化数据
	 */
	@PostConstruct
	public void init() {
		logger.info("--------初始化系统，加载资源---------------------------");
		//如果启用便初始化
		if (sysConfigs.getSysEnableItems().get("redis")) {
			logger.info("启用了redis，执行redis初始化！");
			RedisCacheManager.setConfig(sysConfigs.getRedisConf().addr, sysConfigs.getRedisConf().port,
					sysConfigs.getRedisConf().auth, sysConfigs.getRedisConf().max_total,
					sysConfigs.getRedisConf().max_idle, sysConfigs.getRedisConf().max_wait,
					sysConfigs.getRedisConf().timeout, sysConfigs.getRedisConf().test_on_borrow,
					sysConfigs.getRedisConf().database_num);

			RedisCacheManager.initConfig();
		}

		logger.info("--------初始化系统，加载资源完成------------------------");
	}

	/**
	 * 资源清理
	 */
	@PreDestroy
	public void destroy() {
		logger.info("--------系统关闭前清理资源--------------------------");
		logger.info("----------完成资源清除-----------------------------");
	}

}
